Skip to content

peer: keep a fee bump's turn until the close has taken its offer - #29

Open
2rdzy wants to merge 1 commit into
paulscode:blake2bfrom
2rdzy:rbf-bump-turn-until-applied
Open

2rdzy wants to merge 1 commit into
paulscode:blake2bfrom
2rdzy:rbf-bump-turn-until-applied

Conversation

@2rdzy

@2rdzy 2rdzy commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

Hardening follow-up to #23, requested in review: the approach was proposed in this comment, and the PR asked for as hardening in this one. The fee bumps of one channel take turns, but a bump gave up its turn as soon as its offer was sent, which only queues it. A bump now keeps its turn until the close has taken the offer, so the next bump cannot read the state from before it and send a second offer into LocalOfferSent. The turns map also drops a channel's entry after its last bump.

Problem

sendRbfFeeBump (peer/brontide.go:5222) releases the turn when it returns, right after SendEvent. If the closer is busy with another event at that moment, in practice a peer message, the offer waits in the event buffer and the next bump's CurrentState() can be answered first. That bump then sends its own offer into LocalOfferSent: the closer sends the peer an error and resets, so the bump fails and the close can be retried. Nothing is at risk, and an idle closer takes the event at once (0 stale reads in 3000 tries), so this is hardening rather than a fix for an observed failure.

Reproduction

go test -race -count=1 -run '^TestRbfFeeBumpTurnHeldUntilOfferTaken$' -v ./peer

The test holds the closer inside the signer, in the middle of the offer, and checks that the turn is not free. It tests the property, not an observed failure: two concurrent bumps on a close that can sign ran 300 times without a double offer.

Before

On blake2b 6deb6c9 the new test fails 5 of 5:

Error:      Target error should be in err chain:
            expected: "context deadline exceeded"
            in chain:
Messages:   turn given up before the close took the offer

Change

  • sendRbfFeeBump subscribes to the closer's states before it sends the offer, and keeps the turn until the close shows a new local state (waitRbfOfferTaken). Only a local offer replaces the local state: an event for the remote party keeps it, and the only other sender of SendOfferEvent is the closer's own first offer at ChannelFlushed.
  • The wait also ends when the caller or the peer goes away, when the closer stops, or when the close leaves negotiation.
  • sendRbfCloseEvent reports whether it sent the event, so a bump whose closer was retired does not wait. waitUntilRbfCoastClear returns the local state it saw.
  • rbfFeeBumpSlots counts the bumps that hold or wait for a channel's turn and drops the entry when none is left.

After

The new test passes 10 of 10 under -race, with the TestRbfReconnect* tests and TestRbfFeeBumpSlots.

Test results

Commit 201d11280 on blake2b 6deb6c9.

  • peer, protofsm and lnwallet/chancloser pass under -race; gofmt and vet with and without the dev and RPC tags are clean.
  • Fork checks: pass.
  • BLAKE2b integration tests: 351 pass, 10 skip, 0 fail; rbf_coop_close and rbf_coop_close_disconnect pass.

Caveats

  • The first state read in startRbfChanCloser has the same small window for two CloseChannel calls sent back to back on an active channel. This change does not cover it.
  • If the caller goes away between sending the offer and the close taking it, the turn is given up early.

The fee bumps of one channel take turns, so that a second offer does
not reach a close that waits for the peer's signature of the first,
which stops the closer. A bump gave up its turn as soon as its offer
was sent. Sending only queues the offer: when the closer is busy with
another event at that moment, the next bump can still read the state
from before the offer, and send its own.

A bump now keeps its turn until the close shows a new local state,
which only a local offer causes, or until the caller or the peer goes
away, the closer stops or the close leaves negotiation.
sendRbfCloseEvent reports whether it sent the event, so a bump whose
closer was retired does not wait.

A channel's turn is no longer kept after the last bump that uses it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant